import { http } from "@/utils/http";

// 设备信息接口类型 - 根据后端EquipmentVo实体类
export interface Equipment {
  id?: number;
  tenantId?: number; // 租户ID
  deviceName: string; // 设备名称
  deviceCode: string; // 设备编码
  deviceType: string; // 设备类型
  deviceMaterial: string; // 设备材质
  deviceWeight: string; // 设备重量
  price: number; // 价格
  unit: string; // 单位
  deviceStock: number; // 设备库存
  status: number; // 设备状态
  installDate: string; // 安装日期
  installAddress: string; // 安装地址
  manufacturer: string; // 制造商
  manufacturerAddress: string; // 制造商地址
  manufacturerPhone: string; // 制造商电话
  responsiblePerson: string; // 负责人
  maintenanceUnit: string; // 维护单位
  maintenanceUnitPhone: string; // 维护单位电话
  maintenanceUnitAddress: string; // 维护单位地址
  equipmentMaintainer: string; // 设备维护人
  registrationDate: string; // 登记日期
  remarks: string; // 备注
  maintenanceCount?: number; // 维护次数
  repairCount?: number; // 维修次数
}

// 设备查询参数接口
export interface EquipmentQuery {
  page?: number;
  limit?: number;
  tenantId?: number;
  address?: string;
  deviceName?: string;
  deviceCode?: string;
  deviceType?: string;
  [key: string]: any;
}

// 分页响应接口
interface PageResponse<T> {
  total: number;
  list: T[];
}

// 设备列表响应
export interface EquipmentListResponse {
  code: number;
  data: PageResponse<Equipment>;
  message: string;
}

// 获取设备列表
export const getEquipmentList = (params?: EquipmentQuery) => {
  return http.post<EquipmentListResponse>("/equipment/list", { data: params });
};

// 获取设备详情
export const getEquipmentDetail = (id: number) => {
  return http.get<ApiResponse<Equipment>>("/equipment/info", {
    params: { id }
  });
};

// 添加设备
export const addEquipment = (data?: any) => {
  return http.post<ApiResponse>("/equipment/add", { data });
};

// 更新设备
export const updateEquipment = (equipment: Equipment) => {
  return http.put<ApiResponse>(`/equipment/update/${equipment.id}`, {
    data: equipment
  });
};

// 删除设备
export const deleteEquipment = (id: number) => {
  return http.request<ApiResponse>("delete", "/equipment/delete", {
    params: { id }
  });
};

// 批量删除设备
export const batchDeleteEquipment = (ids: number[]) => {
  return http.request<ApiResponse>("delete", "/equipment/deleteByBatch", {
    data: { ids }
  });
};

// 通用响应接口
export interface ApiResponse<T = any> {
  code: number;
  data?: T;
  message: string;
}
